package org.tgcloud.group.service.manager;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tgcloud.group.core.APPResultMessage;
import org.tgcloud.group.core.ResultMessage;
import org.tgcloud.group.entity.MjMediaParty;
import org.tgcloud.group.repository.MjMediaPartyMapper;
import org.tgcloud.group.web.controller.dto.meidaParty.MediaPartyDTO;
import org.tgcloud.group.web.controller.req.mediaParty.MediaPartyAddReq;
import org.tgcloud.group.web.controller.req.mediaParty.MediaPartyIdReq;
import org.tgcloud.group.web.controller.req.mediaParty.MediaPartyUpdateReq;

import java.util.List;

/**
 * @Author: zhy
 * @Created: 2025-08-25-下午5:52
 * @Description:
 */
@Service
public class MediaPartyManageService {

    @Autowired
    private MjMediaPartyMapper mediaPartyMapper;


    public APPResultMessage<Object, MediaPartyDTO> getMediaPartyList(Integer pageNum, Integer pageSize, String keyword) {
        if (pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum, pageSize);
            List<MediaPartyDTO> list = mediaPartyMapper.selectManageListByKeyword(keyword);
            PageInfo<MediaPartyDTO> tables = new PageInfo<>(list);
            ResultMessage result = ResultMessage.builder().setList(tables.getList()).setAllPageNumber(tables.getPages()).setCount(tables.getTotal());
            APPResultMessage<Object, MediaPartyDTO> message = APPResultMessage.getSuccessMessage();
            message.setResult(result);
            return message;
        }else {
            List<MediaPartyDTO> list = mediaPartyMapper.selectManageListByKeyword(keyword);
            ResultMessage result = ResultMessage.builder().setList(list);
            APPResultMessage<Object, MediaPartyDTO> message = APPResultMessage.getSuccessMessage();
            message.setResult(result);
            return message;
        }
    }

    public APPResultMessage doAddMediaParty(MediaPartyAddReq req) {
        MjMediaParty mediaParty = new MjMediaParty();
        mediaParty.setMediaPartyName(req.getMediaPartyName());
        mediaParty.setMediaPartyPic(req.getMediaPartyPic());
        mediaParty.setStatus((short) 1);
        mediaPartyMapper.insertSelective(mediaParty);
        return APPResultMessage.getSuccessMessage();
    }

    public APPResultMessage doUpdateMediaParty(MediaPartyUpdateReq req) {
        MjMediaParty mediaParty = new MjMediaParty();
        mediaParty.setMediaPartyName(req.getMediaPartyName());
        mediaParty.setMediaPartyPic(req.getMediaPartyPic());
        mediaParty.setId(req.getId());
        mediaPartyMapper.updateByPrimaryKeySelective(mediaParty);
        return APPResultMessage.getSuccessMessage();
    }

    public APPResultMessage doDelMediaParty(MediaPartyIdReq req) {
        mediaPartyMapper.updateDelStatusById(req.getId());
        return APPResultMessage.getSuccessMessage();
    }
}
